package cn.org.book.shop.web.controller.article;

import cn.org.book.shop.article.domain.ApArticleConfig;
import cn.org.book.shop.article.service.IApArticleConfigService;
import cn.org.book.shop.common.annotation.Log;
import cn.org.book.shop.common.core.controller.BaseController;
import cn.org.book.shop.common.core.domain.AjaxResult;
import cn.org.book.shop.common.core.page.TableDataInfo;
import cn.org.book.shop.common.enums.BusinessType;
import cn.org.book.shop.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * APP已发布文章配置Controller
 *
 * @author julywhj
 * @date 2020-11-17
 * @blame Android Team
 */
@RestController
@RequestMapping("/ap/config")
public class ApArticleConfigController extends BaseController {
    @Autowired
    private IApArticleConfigService apArticleConfigService;



    /**
     * 查询APP已发布文章配置列表
     */
    @PreAuthorize("@ss.hasPermi('ap:article-config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApArticleConfig apArticleConfig) {
        startPage();
        List<ApArticleConfig> list = apArticleConfigService.selectApArticleConfigList(apArticleConfig);
        return getDataTable(list);
    }

    /**
     * 导出APP已发布文章配置列表
     */
    @PreAuthorize("@ss.hasPermi('ap:article-config:export')")
    @Log(title = "APP已发布文章配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ApArticleConfig apArticleConfig) {
        List<ApArticleConfig> list = apArticleConfigService.selectApArticleConfigList(apArticleConfig);
        ExcelUtil<ApArticleConfig> util = new ExcelUtil<ApArticleConfig>(ApArticleConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 获取APP已发布文章配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('ap:article-config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(apArticleConfigService.selectApArticleConfigById(id));
    }

    /**
     * 新增APP已发布文章配置
     */
    @PreAuthorize("@ss.hasPermi('ap:article-config:add')")
    @Log(title = "APP已发布文章配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApArticleConfig apArticleConfig) {
        return toAjax(apArticleConfigService.insertApArticleConfig(apArticleConfig));
    }

    /**
     * 修改APP已发布文章配置
     */
    @PreAuthorize("@ss.hasPermi('ap:article-config:edit')")
    @Log(title = "APP已发布文章配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApArticleConfig apArticleConfig) {
        return toAjax(apArticleConfigService.updateApArticleConfig(apArticleConfig));
    }

    /**
     * 删除APP已发布文章配置
     */
    @PreAuthorize("@ss.hasPermi('ap:article-config:remove')")
    @Log(title = "APP已发布文章配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(apArticleConfigService.deleteApArticleConfigByIds(ids));
    }
}
